﻿@model List<WebApplication1.Models.StuInfo>

@{
    ViewBag.Title = "Index";
}

<table class="table table-bordered table-hover">
    <thead>
        <tr>
            <th>学号</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>详情</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
        <tr>
            <td>@item.StuNo</td>
            <td>@item.StuName</td>
            <td>@(item.StuAge>=18?"成年":"未成年")</td>
            <td><a href="#" class="btn btn-danger" data-del="@item.StuNo">删除</a><a href="Xiangq?id=@item.StuNo" class="btn btn-danger">详情</a></td>
        </tr>
        }
    </tbody>
</table>

@section scripts{
    <script type="text/javascript">
        $(function () {
            $("a[data-del]").click(function () {
                var $this = $(this);
                var id = $this.attr("data-del");
                if (!confirm("您确定要删除学号为"+id+"的学生吗？")) return;
                $.post("Delete", { id: id }, function (res) {
                    if (res == true) {
                        $this.closest("tr").remove();
                        alert("删除成功");
                    }
                });
            })
        })
    </script>
    }
